<?php
namespace app\login\model;
use app\common\model\Admin;
use think\Session;
use think\Model;

class LoginModel extends Model
{
	/**
	* 登录操作
	*/
	public static function login($info)
	{
		/*验证码*/
		if(!captcha_check($info['code']))
		{
			return back(config('state.STATUS_CODE_FOUR'),config('state.STATUS_MSG_FOUR'));
		}
		/*账号*/
		$admin = Admin::get(['account'=>$info['username']]);
		if(!$admin)
		{
			return back(config('state.STATUS_CODE_THREE'),config('state.STATUS_MSG_THREE'));
		}
		/*密码验证*/
		if(get_pwd($info['password'],config('overall.PWD_STR')) != $admin['password'])
		{
			return back(config('state.STATUS_CODE_TWO'),config('state.STATUS_MSG_TWO'));
		}
		
		/*保存服务器session*/
		$sessionAdmin['admin_id'] = $admin['admin_id'];
		$sessionAdmin['shop_id'] = $admin['shop_id'];
		$sessionAdmin['admin_type'] = $admin['admin_type'];
		$sessionAdmin['nkname'] = $admin['nkname'];
		$sessionAdmin['account'] = $admin['account'];
		Session::set('admin',$sessionAdmin); /*保存session*/
		
		return back(config('state.STATUS_CODE_ONE'),config('state.STATUS_MSG_ONE'));
	}
}
